﻿@using MerchantTribeStore
@using MerchantTribe.Commerce.Storage;
@model MerchantTribeStore.Areas.AdminContent.Models.FileManagerViewModel

@{
    ViewBag.Title = "File Manager";
    Layout = "~/Views/Shared/_AdminLayoutWithNav.cshtml";
}

@section HeadContent
{
    <script type="text/javascript">
        $(document).ready(function () {

            $('.trashdir').click(function() {
                if (window.confirm('Are you sure?\n\nThe directory AND everything in it will be deleted forever!\n\nTHERE IS NO UNDO FOR THIS DELETE')) 
                {
                    return true;
                }
                return false;
            });

            $('.trashfile').click(function () {
                if (window.confirm('Are you sure?\n\nDelete this file forever!\n\nTHERE IS NO UNDO FOR THIS DELETE')) {
                    return true;
                }
                return false;
            });

        });
    </script>
}
    
@helper RenderDeleteDir(string path)
{
    if (DiskStorage.FileManagerIsSystemPath(path))
    {
        <text>&nbsp;</text>
    }
    else
    {
        <form action="@Url.Content("~/bvadmin/content/filemanager/deletedirectory")" method="post">
            <input type="hidden" name="path" value="@Model.Path" />
            <input type="hidden" name="deletepath" value="@path" />
            <input type="image" src="@Url.Content("~/images/system/TrashCan.png")" alt="Delete Directory" class="trashdir" />
        </form>
    }
}
@helper RenderDeleteFile(string filename)
{        
        <form action="@Url.Content("~/bvadmin/content/filemanager/deletefile")" method="post">
            <input type="hidden" name="path" value="@Model.Path" />
            <input type="hidden" name="filename" value="@filename" />
            <input type="image" src="@Url.Content("~/images/system/TrashCan.png")" alt="Delete File" class="trashfile" />
        </form>
}

@section nav {    
    <div class="controlarea1">
    <form action="@Url.Content("~/bvadmin/content/filemanager/upload")" method="post" enctype="multipart/form-data">
        <h3>Upload Files</h3>
        <input type="file" size="10" name="postedfile" multiple="multiple" /><br />        
        <input type="image" src="../images/buttons/upload.png" alt="Upload File" />
        <input type="hidden" name="path" value="@Model.Path" />
    </form>
    </div>
    <div class="controlarea1">
    <form action="@Url.Content("~/bvadmin/content/filemanager/createdirectory")" method="post">
        <h3>Add New Directory</h3>
        <input type="text" name="newdirectoryname" size="20" />
        <input type="hidden" name="path" value="@Model.Path" />
        <input type="image" src="../images/buttons/submit.png" alt="Add New Directory" />
    </form>
    </div>
}
<h1>File Manager</h1>
@Html.Raw(ViewBag.BreadCrumbsFinal)
<hr />
<table width="100%" class="liststyle1">
@if (Model.AllowParentPath)
{
<tr>
    <td style="width:32px;"><a href="@Url.Content("~/bvadmin/content/filemanager?path=" + Model.ParentPath)"><img src="@Url.Content("~/bvadmin/images/fileicons/folder_up_32.png")" alt="Up One Level" /></a></td>
    <td class="listitem"><a href="@Url.Content("~/bvadmin/content/filemanager?path=" + Model.ParentPath)">&laquo; Up One Level</a></td>
    <td class="listitem" style="width:50px;">&nbsp;</td>
    <td class="listitem" style="width:50px;">&nbsp;</td>
</tr>
}
@foreach (string d in Model.Directories)
{
    <tr>
        <td style="width:32px;"><a href="@Url.Content("~/bvadmin/content/filemanager?path=" + Model.ChildPath(d))"><img src="@Url.Content("~/bvadmin/images/fileicons/folder_32.png")"  alt="@d" /></a></td>
        <td class="listitem"><a href="@Url.Content("~/bvadmin/content/filemanager?path=" + Model.ChildPath(d))">@d</a></td>
        <td class="listitem" style="width:50px;">@RenderDeleteDir(Model.ChildPath(d))</td>
        <td class="listitem" style="width:50px;">&nbsp;</td>
    </tr>
}
@foreach (string f in Model.Files)
{
    <tr>
        <td style="width:32px;"><img src="@Url.Content(Html.FileIconUrl(@f))"  class="shadowed" alt="@f" /></td>
        <td class="listitem"><a href="@Url.Content(Model.PreviewUrl(@f))" alt="@f">@f</a></td>
        <td class="listitem" style="width:50px;">@RenderDeleteFile(f)</td>
        <td class="listitem" style="width:50px;">&nbsp;</td>
    </tr>
}
</table>
